// acidstand.txt
// Sits passive until a character gets withing 4 spaces. Then starts
// spraying acid to range of 8 spaces. Continues until disarmed.
// Cell 0 - The number of levels of acid this mine does. If 0, defaults to 2.
// Cell 1,2 - A stuff done flag. If > 0, this box has been deactivated.
// Cell 3 - DIsarming difficulty. If 0, defaults to 6.

beginobjectscript; 

variables;
short disarmed = 0;
short activated = 0;
short difficulty = 6;
short cur_tick;

body;

beginstate INIT_STATE;
	if ((get_memory_cell(1) > 0) || (get_memory_cell(2) > 0)) {
		if (get_sdf(get_memory_cell(1),get_memory_cell(2)) > 0)
			kill_object(ME,0);
		}
	if (get_memory_cell(3) > 0)	
		difficulty = get_memory_cell(3);
	break;

beginstate DEAD_STATE;

break;

beginstate START_STATE; // crystal dark, waititng
	if (disarmed)
		end();

	if ((activated == 0) && (get_nearest_good_char(4) >= 0)) {
		create_text_bubble("Click. Whirr.");
		set_object_icon(ME,4);
		cur_tick = get_current_tick();
		set_state(3);
		}
break;

beginstate 3; // waiting to spray acid
	if (disarmed)
		set_state(START_STATE);
	if ((cur_tick < get_current_tick()) && (get_ran(1,0,100) < 80)) {
		pc_heard_sound(156);
		run_object_animation(9,0,35);
		set_state(4);
		}
break;

beginstate 4; // spraying acid
	if (disarmed)
		set_state(START_STATE);
	if (am_i_doing_action() == FALSE) {
		create_text_bubble("Spray!");
		pc_heard_sound(124);
		run_sparkles_on_object(ME,5,5,1);							
		if (get_memory_cell(0) == 0)
			status_nearby(15,8,6,2);
			else status_nearby(get_memory_cell(0) * 3 + 8,8,6,2);
		set_state(3);
		}
break;

beginstate USE_STATE;
	if (disarmed) {
		print_str("Disarm Acid Sprayer: You already did.");
		}
	else if (get_stat(21) >= difficulty) {
		print_str("Disarm Acid Sprayer: You manage to shut it off.");
		create_text_bubble("Click.");
		disarmed = 1;
		pc_heard_sound(166);
		kill_object(ME,0);
		award_party_xp(BASE_TRAP_XP - 5,trap_lev_to_xp_lev(difficulty));
		}
		else {
			print_big_str("Disarm Acid Sprayer: Your Mechanics skill isn't high enough. (Difficulty: ",difficulty,").");
			}
break;